import React, { useEffect, useState } from "react";
import { Provider } from "react-redux";
import { ConfigProvider } from "antd";
import zhCN from "antd/es/locale/zh_CN";
import { PersistGate } from "redux-persist/integration/react";
import { ConnectedRouter } from "connected-react-router";
import history from "./store/history";
import { store, persistor } from "./store";
import "../styles/index.less";
import Routes from "./routes";
import { dataHelper } from "~/lib_framework";
import actions from "./store/actions/config";
import StartWeb4 from "./web4"; 

const Web5 = () => (
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <ConnectedRouter history={history}>
        <ConfigProvider locale={zhCN}>
          <Routes></Routes>
        </ConfigProvider>
      </ConnectedRouter>
    </PersistGate>
  </Provider>
);

export default () => {
  let [web5Signal, startWeb5] = useState(false);
  useEffect(() => {
    store.dispatch(actions.setConfig(dataHelper.config));
    StartWeb4();
    startWeb5(true);
  }, []);
  return <>{web5Signal ? <Web5 /> : ""}</>;
};
